package com.zw.transition.controller;


import com.zw.transition.base.BaseController;
import com.zw.transition.common.JsonResult;
import com.zw.transition.entity.User;
import com.zw.transition.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController extends BaseController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     */
    @ResponseBody
    @PostMapping("/login")
    public JsonResult login(User user, HttpSession session) {

        User u = userService.login(user);
        if (u != null) {
            session.setAttribute("user", u);
            //List<Menu> menus = menuService.findMenuByUserId(user.getId());
            return success();
        } else {
            return error("帐号密码错误");
        }
    }

}
